import currentPageObj from '../libs/currentPageObj'
import actLog from '../libs/actLog'
import modelPages from '../libs/modelPages'
import pageCodeMap from '../libs/pageCodeMap'
export default {
	data(){
		return {
			buriedPointActInfo: {
				opened: false,
				show: false,
				pageShowTime: 0,
				pageStayTime: 0
			}
		}
	},
	onLoad(options){
		this.buriedPointActInfo.opened = true
		this.buriedPointActInfo.show = true
		this.buriedPointActInfo.pageShowTime = new Date().getTime()
		var pageUrl = currentPageObj().pageUrl
		if(modelPages.indexOf(pageUrl) === -1){
			pageCodeMap.some(page=>{
				if(page.path === pageUrl){
					actLog({
						shareLockCycle: 24,
						pageCode: page.code,
						itemType: 'pageOpen',
						itemCode: '1',
						itemName: '页面加载事件',
						actCode: '',
						themeCode: '',
						withLoc: true
					})
					return true
				}
			})
		}
	},
	onShow(){
		if(this.buriedPointActInfo.opened === false){
			return
		}
		this.buriedPointActInfo.show = true
		this.buriedPointActInfo.pageShowTime = new Date().getTime()
	},
	onHide(){
		this.buriedPointActInfo.show = false
		this.buriedPointActInfo.pageStayTime += new Date().getTime() - this.buriedPointActInfo.pageShowTime
	},
	onUnload(){
		if(this.buriedPointActInfo.show === false){
			return
		}
		this.buriedPointActInfo.pageStayTime += new Date().getTime() - this.buriedPointActInfo.pageShowTime
		var pageUrl = currentPageObj().pageUrl
		if(modelPages.indexOf(pageUrl) > -1 && pageUrl.indexOf('singlePage') > -1){
			var page = this.pageData ? this.pageData.conData[0] : null
			if(page && page.statStayTime === true){
				actLog({
					shareLockCycle: 24,
					pageCode: page.cid,
					itemType: 'stay',
					itemCode: '4',
					itemName: '页面停留',
					stayTime: this.buriedPointActInfo.pageStayTime/1000,
					actCode: '',
					themeCode: '',
					withLoc: true
				})
			}
		}else{
			var destroyPage = []
			if(destroyPage.indexOf(pageUrl) === -1){
				return
			}
			pageCodeMap.some(page=>{
				if(page.path === pageUrl){
					actLog({
						shareLockCycle: 24,
						pageCode: page.code,
						itemType: 'stay',
						itemCode: '4',
						itemName: '页面停留',
						stayTime: this.buriedPointActInfo.pageStayTime/1000,
						actCode: '',
						themeCode: '',
						withLoc: true
					})
					return true
				}
			})
		}
	}
}